<?php

/**
 * StaffProfile form.
 *
 * @package    erp-dnict
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class StaffProfileForm extends BaseStaffProfileForm
{
  public function configure()
  {
    $this->setWidgets(array(
        'minority_id'                   =>  new sfWidgetFormSelect(array('choices' => $this->getAllItems('Minority'))),
        'religion_id'                   =>  new sfWidgetFormSelect(array('choices' => $this->getAllItems('Religion'))),
        'gov_organization_id'           =>  new sfWidgetFormSelect(array('choices' => $this->getAllItems('GovOrganization'))),
        'contract_type'                 =>  new sfWidgetFormSelect(array('choices' => $this->getAllItems('ContractType'))),
        'job_specialization'            =>  new sfWidgetFormInput(),
        ));

    $this->widgetSchema->setLabels(array(
        'minority_id'                   =>  'Dân tộc:',
        'religion_id'                   =>  'Tôn giáo:',
        'job_specialization'            =>  'Chức vụ:',
        'gov_organization_id'           =>  'Phòng ban:',
        'contract_type'                 =>  'Loại hợp đồng:',
        ));

    $this->setValidators(array(
        'minority_id'                   => new sfValidatorChoice(array('required' => true, 'choices' => array_keys($this->getAllItems('Minority')))),
        'religion_id'                   => new sfValidatorChoice(array('required' => true, 'choices' => array_keys($this->getAllItems('Religion')))),
        'contract_type'                 => new sfValidatorChoice(array('required' => true, 'choices' => array_keys($this->getAllItems('ContractType')))),
        'gov_organization_id'           => new sfValidatorChoice(array('required' => true, 'choices' => array_keys($this->getAllItems('GovOrganization')))),
        'job_specialization'            => new sfValidatorString(array('required' => true)),
        ));
    $this->widgetSchema->setNameFormat('staff_profile[%s]');
  }

  public function getAllItems($object)
  {
    $q = Doctrine_Query::create()
            ->from($object.' o')
            ->where('o.is_active = ?', true);

    if ($object == "Religion")
        $items = array('1' => 'Không');
    $results = $q->execute();
    foreach ($results as $result)
        $items[$result['id']] = $result['name'];

    return $items;
  }

}
